﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Project
{
    public partial class FJxiu : Form
    {
        public int id;
        public FJxiu()
        {
            InitializeComponent();
        }

        private void FJxiu_Load(object sender, EventArgs e)
        {

            string sql = "select * from Room";
            DataTable dt = FrmHotel.DBHelper.SelectForTable(sql);
            this.comboBox1.DisplayMember = "RoomName";
            this.comboBox1.ValueMember = "RoomId";
            this.comboBox1.DataSource = dt;
            s();
        }
        public void s() 
        {
            string sql = "select * from room r , RoomInfo i where r.RoomId = i.RmRoom and i.rmid = " + id;
            SqlDataReader reader = FrmHotel.DBHelper.SelectMore(sql);
            int r = 0;
            if(reader.Read())
            {
                this.textBox1.Text = reader["RmName"].ToString();
                r = Convert.ToInt32(reader["Roomid"]);
            }
            reader.Close();
            comboBox1.SelectedValue = r;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            fjxiu();
        }
        public void fjxiu() 
        {
            string name = this.textBox1.Text;
            int fjid = Convert.ToInt32(this.comboBox1.SelectedValue);
            if(string.IsNullOrEmpty(name))
            {
                MessageBox.Show("请填写完整");
            }
            string sql = string.Format("update RoomInfo set RmName='{0}',RmRoom={1} where RmId={2}", name, fjid, id);
            int result = FrmHotel.DBHelper.ExecuteUpdate(sql);
            if (result > 0)
            {
                MessageBox.Show("修改成功");
                this.Close();
            }
            else 
            {
                MessageBox.Show("修改失败");
            }
        }
    }
}
